package view
{
	import flash.events.Event;
	
	import model.vo.LoginVO;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class LoginPanelMediato extends Mediator implements IMediator
	{

		private static const NAME:String="LoginPanelMediato";

		public function LoginPanelMediato(viewComponent:Object=null)
		{
			super(NAME, viewComponent);
			loginPanel.addEventListener(LoginPanl.TRY_LOGIN,onTryLogin);
		}

		override public function listNotificationInterests():Array
		{
			return [

				LoginProxy.LOGIN_FALLED,
				LoginProxy.LOGIN_SUCCESS

				];
		}
		// 处理Notification 
		override public function handleNotification( note:INotification ):void   
		{ 
			switch ( note.getName() )  { 
				case LoginProxy.LOGIN_FAILED: 
					LoginPanel.loginVO  = new LoginVO( ); 
					loginPanel.loginStatus  = 
					LoginPanel.NOT_LOGGED_IN; 
					break; 
				case LoginProxy.LOGIN_SUCCESS: 
					loginPanel.loginStatus = LoginPanel.LOGGED_IN; 
					break; 
			} 
		}   
		// 用户单击Login按 ， 登 。 钮 尝试 录  
		private function onTryLogin ( event:Event ) : void  {    
			sendNotification( ApplicationFacade.LOGIN, loginPanel.LoginVO ); 
		} 
		// 把viewComponent转 类 化成它真正的 型。
		protected function get loginPanel() : loginPanel
		{ 
			return viewComponent as loginPanel; 
		}
	}
}
